package com.batdream.message.controller;

import com.batdream.message.pojo.Users;
import com.batdream.message.pojo.bo.UserBo;
import com.batdream.message.service.FileService;
import com.batdream.message.utils.JSONResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Wang Chen Peng
 * @date 2018/12/26
 * describe: 文件相关Controller
 */
@Log4j2
@RestController
@RequestMapping("/file")
public class FileController {

    private final FileService fileService;

    @Autowired
    public FileController(FileService fileService) {
        this.fileService = fileService;
    }

    /**
     * 保存上传的base64字符串图片到服务器
     * 并更新用户头像信息
     * @param userBo 用户id base64字符串(图片)
     * @return JSONResult
     */
    @PostMapping("/upload/base64")
    public JSONResult uploadBase64(@RequestBody UserBo userBo){
        try {
            return fileService.uploadBase64(userBo);
        } catch (Exception e) {
            return JSONResult.errorMsg("服务器异常");
        }
    }


}
